Skip to main content

matchText

Type

function

Summary

Returns true if the regex pattern pattern is found in the specified string, false otherwise.

Syntax

matchText(<string>, <pattern> [, <foundTextVarsList>])

Description

Use the matchText function to check whether a string contains a specified pattern.

If the pattern includes a pair of parentheses, the substring matching the part of the pattern inside the parentheses is placed in the first variable in the foundTextVarsList. Additional substrings, matching additional parenthetical expressions within the pattern, are placed in additional variables in the foundTextVarsList. The number of parenthetical expressions in the pattern should match the number of variables in the foundTextVarsList.

If the matchText function returns false, the values of the variables in the foundTextVarsList are not changed.

For example, the following matchText function call extracts the user name and email address from a typical email "From" line:

    matchText(myVar,\"^From: (.*) &lt;(.+@.+)&gt;\",userName,userAddress)

There are two parenthetical expressions in the pattern above:"(.*)" and "(.+@.+)". If the function returns true - that is, if the string in myVar matches the regex pattern - then the substring of myVar that matches the first of these parenthetical expressions is placed in the variable called userName; the second is placed in the variable userAddress.

The string and pattern are always case-sensitive, regardless of the setting of the caseSensitive property. (If you need to make a case-insensitive comparison, use "(?i)" at the start of the pattern to make the match case-insensitive.)

The matchText and matchChunk functions return the same value, given the same string and pattern. The difference between the two is that the matchText function records the text of matched substrings in the optional foundTextVarsList, which the matchChunk function records the character positions of the matched substrings.

Parameters

NameTypeDescription

string

string

pattern

Any expression that evaluates to a regex pattern

foundTextVarsList

The optional foundTextVarsList consists of one or more names of existing variables, separated by commas.

Examples

matchText("Goodbye","bye")
matchText("Goodbye","^Good")
matchText(phoneNumber,"([0-9]+)-([0-9]+-[0-9]+)",areaCode,phone)

command: find, filter

control structure: function

function: matchChunk, value, localNames

glossary: property, return, variable, value, function call, regex pattern, case-sensitive, case-insensitive, function

keyword: string

property: caseSensitive

Compatibility and Support

Introduced

LiveCode 1.0

OS

mac

windows

linux

ios

android

Platforms

desktop

server

mobile

Thank you for your feedback!

Was this page helpful?